IF EXISTS (
	SELECT SPECIFIC_NAME 
	FROM INFORMATION_SCHEMA.ROUTINES 
	WHERE SPECIFIC_SCHEMA = N'testing'
		AND SPECIFIC_NAME = N'prc_GetQuestionGroupComments' 
)
	BEGIN
		DROP PROCEDURE testing.prc_GetQuestionGroupComments
		PRINT 'Dropping testing.prc_GetQuestionGroupComments'
	END
GO

/*-------------------------------------------------------------------------------------
** Name:	prc_GetQuestionGroupComments
** Purpose:	Get top or all comments belong to a question group
** 
** ------------------------------------------------------------------------------------
** Input Parameters: 
** @QuestionGroupId
** @Top
** 
** ------------------------------------------------------------------------------------
** Usage
** EXEC testing.prc_GetQuestionGroupComments '1', '5'
** EXEC testing.prc_GetQuestionGroupComments '1', 'all'
**
** ------------------------------------------------------------------------------------
** Author:    Hau
** Date:      2012-07-08
** Database:  SIVN_OnlineTestingEngine
**
** ------------------------------------------------------------------------------------
** Modifications:
** 2012-07-08	Hau		Create
** ----------------------------------------------------------------------------------*/

CREATE PROCEDURE [testing].[prc_GetQuestionGroupComments]
@QuestionGroupId varchar(20),
@Top varchar(5)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @SQL varchar(600)

	if (@Top = 'all')
		SET @SQL = 'select * from testing.Comment where QuestionGroupId in (' +@QuestionGroupId +')'
	else
		SET @SQL = 'select top(CAST(' + @Top + ' as int)) * 
			from testing.Comment where QuestionGroupId in (' +@QuestionGroupId +')'
	EXEC(@SQL)
END

PRINT 'Created [testing].[prc_GetUserQuestionGroups]'
GO